package com.ntschy.common.valid.datetime;


import cn.hutool.core.util.StrUtil;

import java.util.regex.Pattern;

/**
 * @Author: Ezreal_geng
 * @Description:
 * @Date:Create：2020-11-22 15:52
 * @Modified By：
 */
public class DateTimeValidationUtil {

    private static final Pattern PATTERN = Pattern.compile("^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])|(0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)([ \\t\\n\\x0B\\f\\r])(([0-1]{1}[0-9]{1})|([2]{1}[0-4]{1}))([:])(([0-5]{1}[0-9]{1}|[6]{1}[0]{1}))([:])((([0-5]{1}[0-9]{1}|[6]{1}[0]{1})))$");
    /**
     * 验证日期格式 2021-02-29 23:59:00
     */
    public static boolean isDateTime(String dateTime){
        if (StrUtil.isEmpty(dateTime)) {
            return false;
        } else {
            boolean matches = PATTERN.matcher(dateTime).matches();
            return matches;
        }
    }

}
